package com.easylive.web.controller;

import com.easylive.annotation.RecordUserMessage;
import com.easylive.entity.enums.MessageTypeEnum;
import com.easylive.web.annotation.GlobalInterceptor;
import com.easylive.entity.po.UserAction;
import com.easylive.entity.request.useraction.WebUserActionDoActionReqVO;
import com.easylive.entity.vo.ResponseVO;
import com.easylive.service.UserActionService;
import com.easylive.service.VideoInfoService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: yudaxian
 * @DateTime: 2024/11/23 11:45
 **/
@RestController
@RequestMapping("/userAction")
public class UserActionController extends ABaseController {

    @Resource
    private UserActionService userActionService;

    @Resource
    private VideoInfoService videoInfoService;

    @PostMapping("/doAction")
    @GlobalInterceptor(checkLogin = true)
    @RecordUserMessage(messageType = MessageTypeEnum.LIKE)
    public ResponseVO doAction(@Validated WebUserActionDoActionReqVO reqVO) {


        UserAction userAction = new UserAction();
        userAction.setVideoId(reqVO.getVideoId());
        userAction.setUserId(getTokenUserInfoDto().getUserId());

        userAction.setActionCount(reqVO.getActionCount() == null? 1 : reqVO.getActionCount());
        userAction.setCommentId(reqVO.getCommentId());
        userAction.setActionType(reqVO.getActionType());

        userActionService.saveAction(userAction);

        return getSuccessResponseVO(null);
    }

}
